package com.maxlen.goods.controller;

import com.maxlen.common.utils.PageUtils;
import com.maxlen.common.utils.R;
import com.maxlen.goods.entity.BrandEntity;
import com.maxlen.goods.entity.vo.BrandVO;
import com.maxlen.goods.service.BrandService;
import com.maxlen.common.valid.AddValid;
import com.maxlen.common.valid.UpdateValid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 品牌
 *
 * @author MaxLen
 * @email MaxLen@gmail.com
 * @date 2022-10-27 10:12:58
 */
@RestController
@RequestMapping("goods/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @PostMapping("/list")
    // @RequiresPermissions("goods:brand:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{brandId}")
    // @RequiresPermissions("goods:brand:info")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);
        return R.ok().put("data", brand);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    // @RequiresPermissions("goods:brand:save")
    public R save(@Validated(AddValid.class) @RequestBody BrandVO brandVO){
		brandService.add(brandVO);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    // @RequiresPermissions("goods:brand:update")
    public R update(@Validated(UpdateValid.class) @RequestBody BrandVO brandVO){
		brandService.updateDetail(brandVO);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    // @RequiresPermissions("goods:brand:delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeDetail(Arrays.asList(brandIds));
        return R.ok();
    }

}
